﻿using System;

public class SingleBase<T> where T: SingleBase<T>, new()
{
    private static Lazy<T> _instance = new Lazy<T>(() =>
    {
        var instance = new T();
        instance.Init();
        return instance;
    });
    public static T Instance => _instance.Value;
    /// <summary>
    /// 初始化组件、数据（不需要base.Init）
    /// </summary>
    protected virtual void Init() { }
    /// <summary>
    /// 清空组件、数据（请将base.Init放在清空所有数据后调用）
    /// </summary>
    protected virtual void Clear()
    {
        _instance = null;
    }
}
